package com.chance.cc.crawler.development.bootstrap.dcdapp.forum;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import org.junit.Test;

import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRequestType.*;

/*
*
* 懂车帝
* */
public class DCDForumStart {
    private static final String DOMAIN = "dongchedi";
    private static Proxy proxy = new Proxy();
    static{
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("H7307T4706B25G4D");
        proxy.setPassword("05B4877CC39192C0");

    }
    public static void main(String[] args) {
        //1.车系的采集
        seriesCrawlerRecord();
        //2.问答页面链接采集
       //forumUrl();
        //3.问答页面内容和评论的采集
        //articleUrl();
    }
    public static void seriesCrawlerRecord(){
        String url = "https://www.dongchedi.com/";
        String side = "forum";
        String methodId = "forum";
        CrawlerRequestRecord crawlerRequestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(DOMAIN, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(DOMAIN)
                .httpUrl(url)
                .httpConfig(HttpConfig.me(DOMAIN))
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1,null))
                .releaseTime(System.currentTimeMillis())
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .build();

        CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                .startPageRequest("dcdapp_series_keyword",turnPageItem)
                .httpUrl("http://192.168.1.217:9599/v1/meta/dcdapp/keys?site=realtimeSeries")
                .requestLabelTag(supportSource)
                .requestLabelTag(internalDownload)
                .build();

        crawlerRequestRecord.tagsCreator().bizTags().addDomain(DOMAIN);
        crawlerRequestRecord.tagsCreator().bizTags().addSite(side);
        crawlerRequestRecord.tagsCreator().bizTags().addSiteBiz(side);
        crawlerRequestRecord.tagsCreator().bizTags().addCustomKV("domainName","dongchedi");
        crawlerRequestRecord.tagsCreator().bizTags().addCustomKV(methodId,methodId);
        DevCrawlerController.builder()
                .triggerInfo(DOMAIN,DOMAIN,System.currentTimeMillis(),DOMAIN)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(DOMAIN))
                .consoleResultPipeline("kafka")
                .consoleResultPipeline("redis")
                .fileResultPipeline("kafka","F:\\chance_log\\dcdapp\\kafka_1.log",false)
                .fileResultPipeline("redis","F:\\chance_log\\dcdapp\\redis_1.log",false)
                .requestRecord(crawlerRequestRecord)
                .supportRecord(keywordRecord)
                .build("com.chance.cc.crawler.development.scripts.dcdapp")
                .start();
    }
    public static void forumUrl(){
        String url = "https://www.dongchedi.com/auto/series/4787";
        String side = "forum";
        String methodId = "forum";
        CrawlerRequestRecord crawlerRequestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(DOMAIN, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(DOMAIN)
                .httpUrl(url)
                .httpConfig(HttpConfig.me(DOMAIN))
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*7,null))
                .releaseTime(System.currentTimeMillis())
                //.resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                //.resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .build();

        crawlerRequestRecord.tagsCreator().bizTags().addDomain(DOMAIN);
        crawlerRequestRecord.tagsCreator().bizTags().addSite(side);
        crawlerRequestRecord.tagsCreator().bizTags().addSiteBiz(side);
        crawlerRequestRecord.tagsCreator().bizTags().addCustomKV("domainName","dongchedi");
        crawlerRequestRecord.tagsCreator().bizTags().addCustomKV(methodId,methodId);
        DevCrawlerController.builder()
                .triggerInfo(DOMAIN,DOMAIN,System.currentTimeMillis(),DOMAIN)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(DOMAIN))
                .consoleResultPipeline("redis")
                .fileResultPipeline("redis","F:\\chance_log\\dcdapp\\kafka-8-2_2.log",false)
                .requestRecord(crawlerRequestRecord)
                .build("com.chance.cc.crawler.development.scripts.dcdapp")
                .start();

    }
    public static void articleUrl(){
        String url = "https://www.dongchedi.com/ugc/article/1706880176607240";
        String side = "forum";
        CrawlerRequestRecord crawlerRequestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(DOMAIN, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(DOMAIN)
                .httpUrl(url)
                .httpConfig(HttpConfig.me(DOMAIN))
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1,null))
                .releaseTime(System.currentTimeMillis())
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .build();
        crawlerRequestRecord.setNeedWashPage(true);
        crawlerRequestRecord.tagsCreator().bizTags().addDomain(DOMAIN);
        crawlerRequestRecord.tagsCreator().bizTags().addSite(side);
        crawlerRequestRecord.tagsCreator().bizTags().addSiteBiz(side);
        crawlerRequestRecord.tagsCreator().bizTags().addCustomKV("domainName","dongchedi");
        DevCrawlerController.builder()
                .triggerInfo(DOMAIN,DOMAIN,System.currentTimeMillis(),DOMAIN)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(DOMAIN))
                .consoleResultPipeline("kafka")
                .fileResultPipeline("kafka","F:\\chance_log\\dcdapp\\kafka-8-2_3.log",true)
                .requestRecord(crawlerRequestRecord)
                .build("com.chance.cc.crawler.development.scripts.dcdapp")
                .start();

    }
    @Test
    public void text1(){
        String s = "https://www.dongchedi.com/ugc/article/1706675149351936";
        String url = "https://www.dongchedi.com/ugc/article/";
        String a = "/user/123";
        System.out.println(a.substring(6));
        String[] split = s.split(url);
        System.out.println(split[1]);
    }
}
